#!/usr/bin/ruby
# -*- ruby -*-
#
# http://programmingpraxis.com/2013/01/08/floating-point-rounding/

def round(f, n)
    e = 10 ** n

    return (e * f + 0.5).to_i.to_f / e
end

puts round(1000.0 / 7.0, 3).to_s
puts round(1000.0 / 7.0, 2).to_s
puts round(1000.0 / 7.0, 1).to_s
puts round(1000.0 / 7.0, 0).to_s
puts round(1000.0 / 7.0, -1).to_s
puts round(1000.0 / 7.0, -2).to_s
